package com.iplant.basic.serviceImpl.dao.fmc;

import com.iplant.base.utils.general.CalendarTool;
import com.iplant.base.utils.sql.BaseDAO;
import com.iplant.basic.service.basicenum.bfc.FMCShiftType;
import com.iplant.basic.service.po.fmc.FMCShift;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Calendar;
import java.util.List;

public class FMCShiftDAO extends BaseDAO {

    private static FMCShiftDAO Instance = null;
    private static Logger logger = LoggerFactory.getLogger(FMCShiftDAO.class);

    private FMCShiftDAO() {
        super(FMCShift.class);
    }

    public static FMCShiftDAO getInstance() {
        if (Instance == null)
            Instance = new FMCShiftDAO();
        return Instance;
    }


    public FMCShiftType FMC_GetShiftType(List<FMCShift> wFMCShiftList, Calendar wDate) {
        if (wFMCShiftList == null || wFMCShiftList.size() == 0)
            return FMCShiftType.Default;

        Calendar wClone;

        wFMCShiftList.sort((o1, o2) -> o1.ShiftType - o2.ShiftType);


        for (FMCShift wFMCShift : wFMCShiftList) {
            if(wFMCShift==null||wFMCShift.Active!=1)
                continue;
            wClone = CalendarTool.CloneDateAndTime(wFMCShift.StartTime, wDate);
            if (wFMCShift.StartTime.compareTo(wClone) <= 0 && wFMCShift.EndTime.compareTo(wClone) > 0)
                return FMCShiftType.getEnumType(wFMCShift.ShiftType);

            if(wFMCShift.StartTime.compareTo(wClone) >0)
                return FMCShiftType.getEnumType(wFMCShift.ShiftType);
        }

        return FMCShiftType.Default;
    }




}
